<?php


namespace App\Http\Model\Job;


use Illuminate\Support\Facades\DB;

class PfsHeadQueryClassBalanceModel
{


    /**
     * 更新表记录
     *
     * @param $result
     * @param $list
     */
    public static function save($result, $list)
    {
        $time = date('Y-m-d H:i:s');
        foreach ($result as $val) {
            if (empty($list[$val->classId])) {
                continue;
            }
            DB::table('class_balance')->where('id', $list[$val->classId])->update([
                'pfs_pull_time'         => $time,
                'pfs_surplus_amt'       => $val->surplusAmt,
                'pfs_total_amt'         => $val->totalAmt,
                'pfs_transferred_amt'   => $val->transferredAmt,
                'pfs_transferred_times' => $val->transferredTimes,
            ]);
        }
    }


    /**
     * 需要查询的班级ID
     *
     * @param     $pfsId
     * @param int $offsetId
     *
     * @return array
     */
    public static function classId($pfsId, &$offsetId = 0)
    {
        $list = DB::select('SELECT `id`,`class_id` FROM `class_balance` WHERE `pfs_dw_id`=:pfs_dw_id AND `summarize_time`=:summarize_time AND `id`>:id AND `is_del`=0 LIMIT 500', [
            'pfs_dw_id'      => $pfsId,
            /*只查询当天的班级记录*/
            'summarize_time' => date('Y-m-d'),
            'id'             => $offsetId
        ]);
        if (empty($list)) {
            return [];
        }
        $classId = [];
        foreach ($list as $val) {
            $offsetId = $val->id;
            $classId[] = [
                'id'       => $val->id,
                'class_id' => $val->class_id,
            ];
        }
        return $classId;
    }

}





/**
 * PfsHeadQueryClassBalanceModel.php
 *
 * 说明:
 *
 * 修改历史
 * ----------------------------------------
 * 2021/6/21 17:57:00   操作:创建
 **/
